#Load the library and Create Reference to Library object 
require 'test\unit'
require 'watir'
include Watir
include Test::Unit::Assertions

# define variables
testURL = 'http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/CascadingDropDown/CascadingDropDown.aspx'
ie = Watir::IE.new

puts 'tests execution started'

def checkMakeList(ie)
  make_i=1;
  sleep (3)
  make_a = Array.new(ie.select_list(:id, 'ctl00_SampleContent_DropDownList1').getAllContents)
  make_size = make_a.size
  while make_i<make_size do
    ie.select_list(:id,'ctl00_SampleContent_DropDownList1').set(make_a[make_i])
    sleep(1)
    model_i=1
    model_a = Array.new(ie.select_list(:id, 'ctl00_SampleContent_DropDownList2').getAllContents)
    model_size = model_a.size
    while model_i<model_size do
      ie.select_list(:id,'ctl00_SampleContent_DropDownList2').set(model_a[model_i])
      sleep(1)
      color_i=1
      color_a = Array.new(ie.select_list(:id, 'ctl00_SampleContent_DropDownList3').getAllContents)
      color_size = color_a.size
      while color_i<color_size do
        ie.select_list(:id,'ctl00_SampleContent_DropDownList3').set(color_a[color_i])
        sleep(1)
        assert_equal("You have chosen a "+color_a[color_i]+" "+make_a[make_i]+" "+model_a[model_i]+". Nice car!", ie.span(:id, 'ctl00_SampleContent_Label1').text)
        color_i=color_i+1
      end
      model_i=model_i+1
      sleep(1)
    end
    make_i=make_i+1
    sleep(1)
  end
  return
end


1.times do
  ie.goto testURL
  checkMakeList(ie)
  ie.close
end

puts 'tests execution finished'